package com.lyj.springcloud.order.controller;

import com.lyj.springcloud.entities.CommonResult;
import com.lyj.springcloud.entities.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@RequestMapping("/order")
public class OrderController {

    /**
     * 支付服务url单机版
     *      static final String PAYMENT_URL = "http://localhost:8001";
     */
    static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVICE";// 通过restTemplate负载均衡


    @Autowired
    RestTemplate restTemplate;

    @GetMapping("/create")
    public CommonResult create(@RequestBody Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL ,
                                            payment ,
                                            CommonResult.class);
    }


    @GetMapping("/get/{id}")
    public CommonResult getPayment(@PathVariable("id") String id) {
        return restTemplate.getForObject(PAYMENT_URL + "/payment/getpaymentbyid?id=" + id ,
                                        CommonResult.class );
    }
}
